From: Florian Müllner Date: Thu, 20 Jun 2024 18:46:18 +0000 (+0200) Subject: extensionUtils: Include arrays and objects in serialization X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~173^2^2~212 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=0188c453b9e544ea84e16190991f65db7524cc32;p=gnome-shell.git extensionUtils: Include arrays and objects in serialization We currently only handle simple types when (de)serializing, which means we miss keys like "shell-version" and "session-modes". While there is no immediate use for those, handing arrays and objects will allow to support the newly added "donate" metadata in the Extensions app in the future. https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/6575 Part-of: --- diff --git a/js/misc/extensionUtils.js b/js/misc/extensionUtils.js index dc227801f..09338a182 100644 --- a/js/misc/extensionUtils.js +++ b/js/misc/extensionUtils.js @@ -36,6 +36,7 @@ const SERIALIZED_PROPERTIES = [ 'hasPrefs', 'hasUpdate', 'canChange', + 'sessionModes', ]; /** @@ -52,9 +53,7 @@ export function serializeExtension(extension) { obj[prop] = extension[prop]; }); - let res = {}; - for (let key in obj) { - let val = obj[key]; + function packValue(val) { let type; switch (typeof val) { case 'string': @@ -66,13 +65,28 @@ export function serializeExtension(extension) { case 'boolean': type = 'b'; break; + case 'object': + if (Array.isArray(val)) { + type = 'av'; + val = val.map(v => packValue(v)); + } else { + type = 'a{sv}'; + let res = {}; + for (let key in val) { + let packed = packValue(val[key]); + if (packed) + res[key] = packed; + } + val = res; + } + break; default: - continue; + return null; } - res[key] = GLib.Variant.new(type, val); + return GLib.Variant.new(type, val); } - return res; + return packValue(obj).deepUnpack(); } /** @@ -84,7 +98,7 @@ export function serializeExtension(extension) { export function deserializeExtension(variant) { let res = {metadata: {}}; for (let prop in variant) { - let val = variant[prop].unpack(); + let val = variant[prop].recursiveUnpack(); if (SERIALIZED_PROPERTIES.includes(prop)) res[prop] = val; else